﻿Shader "Dan/UI/UI_SpaceRoll"
{
    Properties
    {
        _MainTex ("MainTex", 2D) = "white" {}
        _ColorOutside ("ColorOutside", Color) = (0.07843138,0.3921569,0.7843137,1)
        _ColorInside ("ColorInside", Color) = (1,0,0,1)
        _ColorRampContrast ("ColorRampContrast", Range(0, 1)) = 0.5
        _Emission ("Emission", Float ) = 1
        _Scale ("Scale", Range(0, 1)) = 1
        _Pitch_RGBA("Pitch_RGBA", Vector ) = (0.5,0.5,0.5,0.5)
        _Roll_RGBA("Roll_RGBA", Vector ) = (3,3,3,3)
        _Offset_RGBA("Offset_RGBA", Vector ) = (0,0.2,0.5,1)
        _Speed_RGBA("Speed_RGBA", Vector ) = (1,-1,0.5,0.75)
        
        _FloaSpeed_A ("FloaSpeed_A", Float ) = 1
        _Amplitude_A ("Amplitude_A", Float ) = 0.5

    }
    
    SubShader
    {

        Tags { "IgnoreProjector"="True"
            "Queue"="Transparent"
            "RenderType"="Transparent" }
        LOD 100    
        Blend SrcAlpha OneMinusSrcAlpha
        ZWrite Off 
 
        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            
            #include "UnityCG.cginc"
            #include "../ShaderLibs/UIFX.cginc"
            #include "../ShaderLibs/UVOperator.cginc"
            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };
            
            struct v2f
            {
                float4 vertex : SV_POSITION;    
                float2 uv : TEXCOORD0;
                
            };

             float4 _ColorOutside;
             sampler2D _MainTex; 
             float4 _MainTex_ST;
             float _Scale;
             float4 _Pitch_RGBA;
             float4 _Roll_RGBA;
             float4 _Offset_RGBA;
             float4 _Speed_RGBA;
             
             float _ColorRampContrast;
             float4 _ColorInside;
             float _Emission;
             float _FloaSpeed_A;
             float _Amplitude_A;
            
            v2f vert ( appdata v )
            {
                
                v2f o;
                UNITY_INITIALIZE_OUTPUT(v2f ,o);
                o.vertex = UnityObjectToClipPos(v.vertex);
                
                o.uv = v.uv;        
                return o;
            }
            
            
            


            fixed4 frag (v2f i ) : SV_Target
            {
                
                float2 uv = i.uv;
                uv =TRANSFORM_TEX(uv, _MainTex);
                float2 pitchUV; float2 uvPitchRoll;//声明需要用到的uv
                float2 rotUV01;float2 rotUV02;float2 rotUV03;float2 rotUV04;
                
                float2 scaleUV =  (_Scale+2*uv-1)/(2*_Scale);//缩放值
                float iconFloated =sin((_Time.y*_FloaSpeed_A))*_Amplitude_A; //A通道内ICON的浮动速度和频率
                //求各通道图形的UV旋转
                PitchRollUV(uv,_Pitch_RGBA.x,_Roll_RGBA.x,_Offset_RGBA.x,_Speed_RGBA.x,scaleUV,pitchUV,uvPitchRoll,rotUV01);
                PitchRollUV(uv,_Pitch_RGBA.y,_Roll_RGBA.y,_Offset_RGBA.y,_Speed_RGBA.y,scaleUV,pitchUV,uvPitchRoll,rotUV02);
                PitchRollUV(uv,_Pitch_RGBA.z,_Roll_RGBA.z,_Offset_RGBA.z,_Speed_RGBA.z,scaleUV,pitchUV,uvPitchRoll,rotUV03);
                PitchRollUV(uv,_Pitch_RGBA.w,_Roll_RGBA.w,_Offset_RGBA.w+iconFloated,_Speed_RGBA.w,scaleUV,pitchUV,uvPitchRoll,rotUV04);
                //色彩渐变
                float colorRamp = saturate(length(scaleUV*1.5-0.75) /_ColorRampContrast);
                float3 finalColor = lerp(_ColorInside.rgb,_ColorOutside.rgb,colorRamp)*_Emission;
                 
                
                float channelR = tex2D(_MainTex,rotUV01).r;
                float channelG = tex2D(_MainTex,rotUV02).g;
                float channelB = tex2D(_MainTex,rotUV03).b;
                float channelA = tex2D(_MainTex,rotUV04).a;


                
                
                

                
                
                float2 rd = float2(_Time.y,_Time.y)*0.001;
                
                float flick = Flick(rd);
                
                float FadeOut = saturate((step(0.5,flick)+(_Scale*2-1)));
                
                


                return fixed4(finalColor,(saturate(channelA+channelR+channelG+channelB)*FadeOut));
            
                
               
                

                


                
                
            }
            ENDCG
        }
    }
    
    
    
}
